# coding=utf-8
from venusdemilo import db_drivers

insert_string = ''

class DbDumper(object):
    def __init__(self):
        self.db_driver = db_drivers.MySqlDriver(
            host='localhost', user='root', passwd='root1234', db='scrapydb'
        )

    def dump(self, item):

        return self.save_to_db(self.db_driver, item)


    def save_to_db(self, db_driver, item): #{title, content, url}
        item_tuple = (item['title'], item['content'], item['spider'], item['category'], item['tag'], item['url'], item['referer'], item['issue_date'], item['source'])
        db_driver.insert(insert_string, item_tuple)

        return item